/*
 * @Description:
 * @Author: wangfuwei
 * @Date: 2020-12-04 00:18:09
 * @LastEditors: wangfuwei
 * @LastEditTime: 2020-12-16 19:35:05
 * @FilePath: /horizon-frontend/src/components/Confirm/index.js
 */
import Confirm from "./Confirm.vue";

let instance;
export default {
  install(Vue) {
    Vue.prototype.$confirm = (config = {}) => {
      // 判断是否已经创建
      if (instance) {
        instance.vm.$el.parentNode.removeChild(instance.vm.$el);
      }
      const newConfirm = Vue.extend(Confirm);
      instance = new newConfirm({
        propsData: {
          ...config,
          value: false,
        },
        mounted() {
          // hack 延迟100毫秒取消鼠标点击位置记录
          setTimeout(() => {
            this.value = true;
          }, 100);
        },
      });
      instance.id = "confirm";
      instance.vm = instance.$mount();
      document.body.appendChild(instance.vm.$el);
      return instance.vm;
    };
  },
};
